package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 1/17/21 1:09 PM
 */
public class _1232_缀点成线_01 {

    public boolean checkStraightLine(int[][] coordinates) {

        if (coordinates == null || coordinates.length <= 1) {

            return true;
        }

        // x1 -x2
        int x12 = coordinates[0][0] - coordinates[1][0];
        // y1 - y2
        int y12 = coordinates[0][1] - coordinates[1][1];

        for (int i = 2; i < coordinates.length; i++) {

            /**
             * 使用乘法，不要使用除法，除法要判断分母是否为零
             * (y2-y3)*(x1-x2) == (x2 - x3)*(y1 - y2)
             */
            if ((coordinates[i-1][1] - coordinates[i][1])*x12 != (coordinates[i-1][0] - coordinates[i][0])* y12) {

                return false;
            }

        }

        return true;
    }

  public static void main(String[] args) {
    //

      _1232_缀点成线_01 line = new _1232_缀点成线_01();

      boolean result = line.checkStraightLine(new int[][]{{0, 0}, {0, 1}, {0,-1}});

        System.out.println(result);
  }

}
